package com.wjc.demo.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wjc.demo.dto.TestDTO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @ Description：TODO
 * @ Author：wzj
 * @ Date：2019/3/9 10:21
 */
@Controller
@RequestMapping("/testController")
@PropertySource({"classpath:application1.properties"})
public class TestController {

    @Value("${test.name}")
    private String testname;

    @Value("${test.name11}")
    private String testname1;

    @ResponseBody
    @RequestMapping("/test")
    public String test(HttpSession session){
        System.out.println(testname);
        System.out.println(testname1);
        System.out.println("测试宿舍a enen"+session.getId());
        return "ok"+session.getId();
    }

    @RequestMapping("/goTest")
    public ModelAndView goTest(){
        ModelAndView mv=new ModelAndView("test");
        return mv;
    }

    @ResponseBody
    @RequestMapping("/testComplex")
    public String testComplex(@RequestBody TestDTO testDTO, HttpServletRequest request){
        JSONObject jsonObject=new JSONObject();
        System.out.println(testDTO.toString());
        jsonObject.put("code",true);
        return jsonObject.toJSONString();
    }

    @ResponseBody
    @RequestMapping("/testStation")
    public String testStation(){

        JSONArray jsonArray=new JSONArray();

        for(int i=0;i<100;i++){
            Map map=new HashMap();
            map.put("name","南曹村"+i);
            int k=100-i+1;
            if(k<10){
                map.put("id","F170"+k);
            } else {
                map.put("id","F17"+k);
            }
            map.put("latitude","252713");
            map.put("longitude","1191737");
            jsonArray.add(map);
        }

        return jsonArray.toJSONString();
    }

    @ResponseBody
    @RequestMapping("/testData")
    public String testData(String staId,String starttime,String endtime){
        System.out.println(staId+" "+starttime+" "+endtime);
        JSONArray jsonObject= JSONArray.parseArray("[[\"39538CA6ECFA4AC89B086C140746A5E9\",\"d:\\\\apache-tomcat-6.0.41\\\\webapps\\\\HourInformation\\\\ZDZAIEFZ\\\\AI201907302345.EFZ\",\"2019/07/31 08:26:00\",\"F1817\",\"25.648611\",\"119.68528\",\"184.0\",\"185.0\",\"4\",\"2019/07/30 23:45:00\",\"350\",\"10.1\",\"350\",\"10.2\",\"346\",\"11.5\",\"2325\",\"352\",\"102\",\"349\",\"15.8\",\"2315\",\"0.0\",\"27.0\",\"27.0\",\"2337\",\"26.7\",\"2301\",\"094\",\"094\",\"2334\",\"335\",\"26.0\",\"988.6\",\"988.6\",\"2340\",\"988.3\",\"2301\",null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,\"1009.6\",null,null,null]]");
        return jsonObject.toJSONString();
    }
}
